package com.fhz.a2002;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        User.Builder builder = new User.Builder();
        builder.setName("haha").setAddress("哈哈");

        User build = builder.build();


//        new AlertDialog.Builder(this);
    }

    public void one(View view) {

        //要的AlertDialog 对话框
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.mipmap.ic_launcher);

        builder.setTitle("我是标题");

        builder.setMessage("我是提示内容");

        //ctrl+p
        builder.setPositiveButton(R.string.app_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //两下tab
                Toast.makeText(MainActivity.this, "我是确定", Toast.LENGTH_SHORT).show();
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "我是取消", Toast.LENGTH_SHORT).show();
            }
        });

        //要创建AlertDialog对象
        AlertDialog alertDialog = builder.create();

        //实现对话框
        alertDialog.show();

        //隐藏对话框
//        alertDialog.hide();

    }

    public void two(View view) {
        //要的AlertDialog 对话框
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle("我是标题");

        //ctrl+p
        builder.setPositiveButton(R.string.app_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //两下tab
                Toast.makeText(MainActivity.this, "我是确定", Toast.LENGTH_SHORT).show();
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "我是取消", Toast.LENGTH_SHORT).show();
            }
        });

        String[] arr = {"生存","灭亡","是个问题"};


        builder.setSingleChoiceItems(arr, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, arr[which], Toast.LENGTH_SHORT).show();
            }
        });

        //要创建AlertDialog对象
        AlertDialog alertDialog = builder.create();

        //实现对话框
        alertDialog.show();

    }

    //多选
    public void three(View view) {

        //要的AlertDialog 对话框
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle("我是标题");

        //ctrl+p
        builder.setPositiveButton(R.string.app_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //两下tab
                Toast.makeText(MainActivity.this, "我是确定", Toast.LENGTH_SHORT).show();
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "我是取消", Toast.LENGTH_SHORT).show();
            }
        });

        String[] arr = {"生存","灭亡","是个问题"};
        boolean[] boo = {true,true,false};

        builder.setMultiChoiceItems(arr, boo, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                if(isChecked){
                    Toast.makeText(MainActivity.this, arr[which], Toast.LENGTH_SHORT).show();
                }
            }
        });

        //要创建AlertDialog对象
        AlertDialog alertDialog = builder.create();

        //实现对话框
        alertDialog.show();

    }

    public void four(View view) {

        //要的AlertDialog 对话框
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle("我是标题");

        //ctrl+p
        builder.setPositiveButton(R.string.app_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //两下tab
                Toast.makeText(MainActivity.this, "我是确定", Toast.LENGTH_SHORT).show();
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "我是取消", Toast.LENGTH_SHORT).show();
            }
        });


        //布局加载器(可以把一个布局文件,变成一个view)
        View inflate = LayoutInflater.from(this).inflate(R.layout.meinv_layout, null, false);

        builder.setView(inflate);


        //要创建AlertDialog对象
        AlertDialog alertDialog = builder.create();

        //实现对话框
        alertDialog.show();
    }

    public void five(View view) {
        ProgressDialog progressDialog = new ProgressDialog(this);

        //有精度
//        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

        //文件的大小
        progressDialog.setMax(100);
        progressDialog.setProgress(20);
        progressDialog.setSecondaryProgress(10);

        progressDialog.setMessage("正在下载");

        //定时器
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            int progress = 0;
            @Override
            public void run() {
                if(progress >= 100){
                    timer.cancel();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            progressDialog.hide();
                        }
                    });
                }
                progress += 10;
                progressDialog.setProgress(progress);
            }
        },0,1000);

        progressDialog.show();

    }

    public void six(View view) {

        //操作日期
        Calendar calendar = Calendar.getInstance();
//        int i = calendar.get(Calendar.YEAR);


        DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            //
            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
//                String.valueOf(year).concat("年").concat(String.valueOf(month).concat(String.valueOf()))
                StringBuffer stringBuffer = new StringBuffer();
                stringBuffer.append(year);
                stringBuffer.append("年");
                stringBuffer.append(month+1);
                stringBuffer.append("月");
                stringBuffer.append(dayOfMonth);
                stringBuffer.append("日");

                Toast.makeText(MainActivity.this,stringBuffer.toString(), Toast.LENGTH_SHORT).show();
            }
        },calendar.get(Calendar.YEAR) , calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));

        datePickerDialog.show();
    }


    public void seven(View view) {
        Calendar calendar = Calendar.getInstance();

        TimePickerDialog timePickerDialog = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                //错误的字符串演示
                Toast.makeText(MainActivity.this, hourOfDay+"点"+minute+"分", Toast.LENGTH_SHORT).show();
            }
        }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false);

        timePickerDialog.show();
    }

    public void eight(View view) {
        MyDialog myDialog = new MyDialog(this);

        myDialog.setTitle("标题");
        myDialog.setMessageStr("哈哈");

        myDialog.setMyListener(new MyDialog.MyListener() {
            @Override
            public void onClick() {
                Toast.makeText(MainActivity.this, "哈哈哈哈哈哈", Toast.LENGTH_SHORT).show();
            }
        });

        myDialog.setMyNoListener(new MyDialog.MyNoListener() {
            @Override
            public void onClick() {
                Toast.makeText(MainActivity.this, "nonononon", Toast.LENGTH_SHORT).show();

            }
        });


        myDialog.show();
    }
}